package cn.com.hbhgkj.web.struts2;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import cn.com.hbhgkj.bussiness.CopyrightApplicationService;
import cn.com.hbhgkj.common.ServiceException;
import cn.com.hbhgkj.pojo.CopyrightApplication;

public class CopyrightApplicationAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String preSubmit() {
		try {
			if (copyrightApplication != null
					&& copyrightApplication.getId() != null) {
				copyrightApplication = copyrightApplicationService
						.loadById(copyrightApplication.getId());
			}

			this.success = true;
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
			return "review_failed";
		}
		return "preSubmit_success";
	}
	
	public String preReview() {
		try {
			if (copyrightApplication != null
					&& copyrightApplication.getId() != null) {
				copyrightApplication = copyrightApplicationService
						.loadById(copyrightApplication.getId());
			}

			this.success = true;
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
			return "review_failed";
		}
		return "preReview_success";
	}

	public String submit() {
		try {
			copyrightApplication.setApplicant(this.getLoggedInUser());
			copyrightApplicationService.submit(copyrightApplication);

			this.success = true;
			this.addActionMessage("保存成功，如需修改请在申请记录中进行修改!");
		} catch (ServiceException e) {
			this.success = false;
			this.addActionMessage(e.getMessage());
			return "review_failed";
		}
		
		return "review_success";
	}

	public String appliedRecords() {
		try {
			listCopyrightApplication = copyrightApplicationService
					.findByApplicant(this.getLoggedInUser(), pagination);
		} catch (ServiceException e) {
			this.success = false;
			this.message = e.getMessage();
		}
		return SUCCESS;
	}

	private CopyrightApplication copyrightApplication;

	private List<CopyrightApplication> listCopyrightApplication;

	public List<CopyrightApplication> getListCopyrightApplication() {
		return listCopyrightApplication;
	}

	public void setListCopyrightApplication(
			List<CopyrightApplication> listCopyrightApplication) {
		this.listCopyrightApplication = listCopyrightApplication;
	}

	public CopyrightApplication getCopyrightApplication() {
		return copyrightApplication;
	}

	public void setCopyrightApplication(
			CopyrightApplication copyrightApplication) {
		this.copyrightApplication = copyrightApplication;
	}

	private CopyrightApplicationService copyrightApplicationService;

	@JSON(serialize = false)
	public CopyrightApplicationService getCopyrightApplicationService() {
		return copyrightApplicationService;
	}

	public void setCopyrightApplicationService(
			CopyrightApplicationService copyrightApplicationService) {
		this.copyrightApplicationService = copyrightApplicationService;
	}

}
